package com.codeforces;

import java.util.Scanner;

public class B1446 {
    Scanner in = new Scanner(System.in);
    private void slove(){
        int n = in.nextInt(),m = in.nextInt();
        char[] A = in.next().toCharArray();
        char[] B = in.next().toCharArray();
        int[][] dp = new int[n + 1][m + 1];
        int res = 0;
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= m;j++){
                dp[i][j] = Math.max(dp[i][j],dp[i - 1][j] - 1);
                dp[i][j] = Math.max(dp[i][j],dp[i][j - 1] - 1);
                if(A[i - 1] == B[j - 1]){
                    dp[i][j] = Math.max(dp[i][j],dp[i - 1][j - 1] + 2);
                }
                res = Math.max(dp[i][j],res);
            }
        }
        System.out.println(res);
    }
    public static void main(String[] args) {
        B1446 s = new B1446();
        s.slove();
    }
}

